//
//  BCSettingCacheManager.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2018/12/29.
//  Copyright © 2018 guoshikeji. All rights reserved.
//

#import "BCSettingCacheManager.h"

@implementation BCSettingCacheManager

static BCSettingCacheManager *_settingCacheManager = nil;
+ (instancetype)sharedCache {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (!_settingCacheManager) {
            _settingCacheManager = [[BCSettingCacheManager alloc] init];
        }
    });
    return _settingCacheManager;
}

- (NSUInteger)getCacheSize {
    NSUInteger size = [[SDImageCache sharedImageCache] getSize];
    self.needClear = size>0;
    return size;
}
- (NSString *)getCacheSizeString {
    NSUInteger size = [self getCacheSize];
    //
    double kbSize = size/1024;
    if (kbSize<1024.0) {
        return [NSString stringWithFormat:@"%.0fKB",kbSize];
    }
    double mSize = kbSize/1024;
    if (mSize<1024.0) {
        return [NSString stringWithFormat:@"%.1fM",mSize];
    }
    double gSize = mSize/1024;
    if (gSize<1024.0) {
        return [NSString stringWithFormat:@"%.1G",gSize];
    }
    double tSize = gSize/1024;
    return [NSString stringWithFormat:@"%.1fT",tSize];
}


- (void)clearCacheComplete:(SettingCacheClearComplete)compelte {
    [[SDImageCache sharedImageCache] clearDiskOnCompletion:^{
        if (compelte) {
            compelte();
        }
    }];
}

@end
